<template>
  <div class="wrapper" @click="clickBox">
    <div class="goods-box">
      <div class="goods-box-header">
        <img :src="data.image" alt="" />
        <div class="goods-box-header-right">
          <div class="goods-box-header-title">
            <span class="name">{{data.name}}</span>
            <span class="model">{{data.model}}</span>
            <span class="pai">{{data.pai}}</span>
          </div>
          <div class="goods-box-header-property">
            <span>{{data.property.split("-")[0]}}</span>
            <i class="iconfont icon-dian"></i>
            <span>{{data.property.split("-")[1]}}</span>
            <i v-if="data.property.split('-').length==3" class="iconfont icon-dian"></i>
            <span v-if="data.property.split('-').length==3">{{data.property.split("-")[2]}}</span>
          </div>
        </div>
      </div>
      <div class="goods-box-footer">
        <div class="goods-box-footer-title">
          <div class="left">
            <div class="left-title">
              <span class="left-title-name">{{data.platform}}</span>
              <span class="left-title-fraction">{{data.score}}分</span>
              <i class="iconfont icon-right"></i>
            </div>
            <div class="left-tag">
              <div>{{data.tag.split("-")[0]}}</div>
              <div v-if="data.tag.split('-').length>=2">{{data.tag.split("-")[1]}}</div>
            </div>
            <div class="left-blue">芝麻信用|免押金</div>
          </div>
          <div class="right">
            <div class="right-price">
              <span>￥</span>
              <span>{{data.price}}</span>
              <span>/天</span>
            </div>
            <div class="right-total">总价￥2972</div>
          </div>
        </div>
        <div class="goods-box-footer-bottom">
          <div class="goods-box-footer-bottom-distance">
            <span class="num">{{data.distance.split('-')[0]}}</span>
            <i class="iconfont icon-dian"></i>
            <span class="city">{{data.distance.split('-')[1]}}</span>
          </div>
          <span class="goods-box-footer-bottom-carList">{{data.shopNum}}个车行
            <i class="icon-xiala iconfont"></i>
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "CarListGoodsBox",
  props: {
    data:{
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {};
  },
  methods: {
    clickBox (e) {
      const carList = document.querySelector(".goods-box-footer-bottom-carList")
      // 如果点击的不是车行列表，则跳转到订车页面
      if (carList !== e.target) {
        this.$router.push({path:"/orderCar",query:{id:this.data.id}})
      } 
    }
  },
};
</script>

<style lang="scss" scoped>
.wrapper {
  width: 285px;
  height: 220px;
  background: white;
  padding: 0 10px;
  margin-bottom: 15px;
  .goods-box {
    .goods-box-header {
      display: flex;
      border-bottom: 1px solid #f2f3f6;
      img {
        width: 125px;
        height: 80px;
        margin-right: 10px;
      }
      .goods-box-header-right {
        height: 80px;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        .goods-box-header-title {
          display: flex;
          align-items: center;
          font-size: 16px;
          font-weight: 700;
          color: #000;
          .name {
            padding-right: 5px;
            line-height: 1;
          }
          .model {
            line-height: 1;
          }
          .pai {
            background: #5ca5ff;
            font-size: 10px;
            margin-left: 3px;
            color: white;
            line-height: 1;
            padding: 2px;
            border-radius: 3px;
          }
        }
        .goods-box-header-property {
          span {
            font-size: 10px;
            color: #999999;
          }
          .iconfont {
            font-size: 10px;
            color: #999999;
          }
        }
      }
    }

    .goods-box-footer {
      &-title {
        display: flex;
        margin-top: 20px;
        .left {
          flex: 3;
          &-title {
            display: flex;
            align-items: center;
            margin-bottom: 10px;
            &-name {
              font-size: 15px;
              font-weight: 700;
              margin-right: 4px;
            }
            &-fraction {
              font-size: 10px;
              color: #5ca5ff;
              line-height: 1;
              margin-top: 2px;
            }
          }
          &-tag {
            display: flex;
            margin-bottom: 5px;
            div {
              height: 10px;
              line-height: 10px;
              padding: 2px;
              font-size: 12px;
              color: #b3afaf;
              border: 1px solid #b3afaf;
              text-align: center;
              margin-right: 3px;
            }
          }
          &-blue {
            color: #1677ff;
            border: 1px solid rgba(22,119,255,.5);
            font-size: 13px;
            padding: 2px;
            text-align: center;
            width: 101px;
            height: 15px;
            line-height: 15px;
          }
        }
        .right {
          flex: 2;
          padding-top: 10px;
          &-price {
            display: flex;
            justify-content: end;
            align-items: center;
            span:nth-child(1) {
              color: #ff3434;
              font-size: 10px;
              margin-right: 3px;
            }
            span:nth-child(2) {
              color: #ff3434;
              font-size: 20px;
              font-weight: 700;
              margin-right: 2px;
            }
            span:nth-child(3) {
              color: #999;
              font-size: 12px;
            }
          }
          &-total {
            color: #999;
            font-size: 10px;
            font-weight: 500;
            text-align: end;
          }
        }
      }
      .goods-box-footer-bottom {
        margin-top: 15px;
        display: flex;
        align-items: flex-end;
        justify-content:space-between;
        font-size: 10px;
        &-distance {
          height: 16px;
          color: #999;  
          width: 190px;
          padding-top: 2px;       
          .iconfont {
            font-size: 10px;
          }
        }
        &-carList {
          color: #ff3434;
          height: 14px;
          width: 72px;
          line-height: 14px;
          background-color: #ffeaea;
          padding: 3px;
          text-align: center;
          .iconfont {
            font-size: 16px;
          }
        }
      }
    }
  }
}
</style>